<!--<a href="#/layui/fenhuiguanli" class="layui-btn layui-btn-xs layui-btn-primary" style="margin: 20px 0 20px 30px;">
  <i class="layui-icon">&#xe65c;</i>
</a>-->


<!--<div class="layui-card-body">-->
	<div class="layui-fluid" style="padding:0;">
		<div class="layui-card">
			<div class="layui-body-header">
				变更等级积分
			</div>
          <!--<div class="layui-card-header">
            <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-primary" id="search_hash">
              <i class="layui-icon">&#xe615;</i>
            </a>
          </div>-->
          <div class="layui-card-body" style="padding:0">
            <table id="demo_hash" lay-filter="test"></table>
            <script type="text/html" id="barDemo_hash">
              <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
              <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> -->
              <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
          </div>
          <form action="" class="layui-form">
    <div class="layui-col-md10">

     		
     		
     		
     		
     	</div>
     	
     	
	      <div class="layui-form-item">
					<div class="layui-form-label">当前会员ID：</div>
					<div class="layui-input-block">
						<input class="layui-input nowId" disabled="disabled"/>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-form-label">当前会员用户名：</div>
					<div class="layui-input-block ">
						<input class="layui-input nowName" disabled="disabled"/>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-form-label">当前积分：</div>
					<div class="layui-input-block ">
						<input class="layui-input nowScore" disabled="disabled"/>
					</div>
					
				</div>
				<div class="layui-form-item">
					<div class="layui-form-label">变更积分：</div>
					<div class="layui-input-block">
						<table  class="layui-table" lay-skin="nob">
	      						<tbody>
	      							<tr>
	      								<td>
	      									<select name="changeMoney" lay-filter="mon" >
													  <option value="1">增加</option>
													  <option value="0">减少</option>
													</select>   
	      								</td>
	      								<td><input type="text" name="money" required class="layui-input money" ><span class="moneyWarn">*</span></td>
	      								
	      							</tr>
	      						</tbody>
	      					</table>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-form-label">备注：</div>
					<div class="layui-input-block ">
						<input type="text" name="else" placeholder="请输入" class="layui-input memo"></input>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-form-label"></div>
					<div class="layui-input-block ">
						<a href="#/layui/memberList" class="back layui-btn layui-btn-primary">返回列表</a>
						<button type="button" class="confirm layui-btn ">确定</button>
	      		
					</div>
				</div>
	      
	      <div class="layui-col-xs12 userInfo" style="margin-top:0">
	      	
	      	
	      	
	      	<!--<table class="layui-table	" lay-size="lg">
	      		<tbody>
	      			<tr>
	      				<th>当前会员ID：</th>
	      				<th class="nowId"></th>
	      			</tr>
	      			<tr>
	      				<th>当前会员用户名：</th>
	      				<th class="nowName"></th>
	      			</tr>
	      			<tr>
	      				<th>当前积分：</th>
	      				<th class="nowScore"></th>
	      			</tr>
	      			<tr>
	      				<th>变更积分：</th>
	      				<th>
	      					
	      						 
	      					
	      					<table  class="layui-table" lay-skin="nob">
	      						<tbody>
	      							<tr>
	      								<td>
	      									<select name="changeMoney" lay-filter="mon" >
													  <option value="1">增加</option>
													  <option value="0">减少</option>
													</select>   
	      								</td>
	      								<td><input type="text" name="money" required class="layui-input money" ><span class="moneyWarn">*</span></td>
	      								
	      							</tr>
	      						</tbody>
	      					</table>
	      					
	      				</th>
	      			</tr>
	      			<tr>
	      				<th>备注：</th>
	      				<th><input type="text" name="else" placeholder="请输入" class="layui-input memo"></input></th>
	      			</tr>
	      		</tbody>
	      	</table>-->
	      	<!--<div class="userInfoBtns">
	      		<button type="button" class="confirm layui-btn layui-btn-primary">确定</button>
	      		<a href="#/layui/memberList" class="back layui-btn">返回列表</a>
	      	</div>-->
	      	
	      </div>
		
		
	      
      	</form>
          
      	</div>
      </div>
    <!--</div>-->
      
      
      





		
      
<script type="text/html" id="search_tpl_hash">
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <label class="layui-form-label">变更日期</label>
      <div class="layui-input-block">
        <div class="layui-inline"> 
				  <input type="text" name="handleDate" class="layui-input" id="test1">
				</div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">变更类型</label>
      <div class="layui-input-block">
        <select name="changeType">
          <option value="0">全部</option>
          <option value="1">后台提值</option>
          <option value="2">后台冲值</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="formDemo_hash"><i class="layui-icon">&#xe615;</i> 搜索</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>
  </form>
</script>
<script>
  
      	let nowId = document.getElementsByClassName("nowId");
      	let nowName = document.getElementsByClassName("nowName");
      	let nowScore = document.getElementsByClassName("nowScore");
      	let money = document.querySelector(".money");
      	let memo = document.querySelector(".memo");
      	let score = '';
      	let mon = 1;
      	let name = '';
      	let changeObj='';
      	let memId = '';
//    	let confirm = document.getElementsByClassName("confirm");
      	
      	
  layui.config({
    base: '/src/js/'
  }).use(['jquery', 'mockjs', 'table', 'sidebar', 'form' , 'route' , 'laydate'], function () {
    var $ = layui.jquery,
      layer = layui.layer,
      table = layui.table,
      sidebar = layui.sidebar,
      route = layui.route,
      params = route.params(),
      form = layui.form;
      
      
      renderForm();
      
      $(".add").click(function(){
      	window.location.href="#/layui/addFHlevJifen?id="+params.id;
      })
      
      let _obj = {
      		"Guid": "00000000-0000-0000-0000-000000000000",
				  "OperateType": '',
				  "CurrentScore": 0,
				  "OperateScore": 0,
				  "LastOperateScore": 0,
				  "Date": getNowFormatDate(),
				  "Memo": "",
				  "MemLoginId": '',
				  "CreateUser": "",
				  "CreateTime": "",
//				  "CircleGuid": params.id,
				  "IsDeleted": 0
      	}
    //第一个实例
    
//  等级改变
    function level(obj,s){
    	DBHelper.GetA("GetXn_RankByCategoryId?id=0",function(data){
    		console.log("等级",data)
    		let tempS = 0;
    		let tempId = '';
    		let temName = ''
    		data.sort(function(a,b){
    			return a.Score - b.Score
    		})
    		data.forEach((el,index)=>{
    			if(s>=el.Score){
    				
    					tempId = el.Guid;
    					tempS=el.Score;
    					temName = el.Name;
    			}
    		})
    		obj.RankGuid = tempId;
    		obj.RankName = temName;
    	},function(data){
    		console.log(data)
    	})
    }
    


    $('#search_hash').on('click', function () {
      var that = this;
      // console.log($('#search_tpl_hash').html());
      sidebar.render({
        elem: that,
        content: $('#search_tpl_hash').html(),
        title: '搜索',
        shade: true,
        // shadeClose:false,
        // direction: 'left'
        // dynamicRender: false,
        // url: 'views/member/all/search.html',
        width: '500px', //可以设置百分比和px
        done: function () {
          console.log('ccc');
          form.render();
          
          laydate.render({
				    elem: '#test1',
				    type: 'datetime',
				    range: true
				  });

          //监听提交
          form.on('submit(formDemo_hash)', function (data) {
            // layer.msg(JSON.stringify(data.field));
            table.reload('demo_hash', {
              where: {
					      	"MemLoginId": memId,
					//			  "CircleGuid": params.id,
								  "StartTime": $("input[name='handleDate']").val().split(" - ")[0],
								  "EndTime": $("input[name='handleDate']").val().split(" - ")[1],
								  "OperateType": 2,
					      },
            });
            return false;
          });
        }
      });
    });
    
    
//  获取会员信息
    DBHelper.Get("Admin_Xn_Member?id="+params.id,function(data){
    	console.log(data)
    	memId = data.MemLoginId;
    	_obj.MemLoginId = data.MemLoginId;
    	$(".nowId").val(data.MemLoginId);
//  	nowId.value = data.MemLoginId;
    	$('.nowName').val(data.RealName);
    	$('.nowScore').val(data.RankScore);
    	score = parseFloat(data.RankScore);
    	changeObj = data;
    	
			table.render({
      method: 'post',
      // size: 'sm',
      limit: 3,
      limits: [10,20,30],
      elem: '#demo_hash',
      height: '230',
      contentType: 'application/json',
      url: 'https://xnsmb.xnsoft.net.cn/api/Filtrate_Xn_RankScoreModifyLog', //数据接口
      parseData: function(res){
      	return {
      		'code':0,
      		'count':res.TotalCount,
      		"data":res._Data
      	};
      },
      where: {
      	"MemLoginId": memId,
//			  "CircleGuid": params.id,
			  "StartTime": "",
			  "EndTime": "",
			  "OperateType": 2,
      },
      request: {
		    pageName: 'CurrentPage' //页码的参数名称，默认：page
		    ,limitName: 'PageSize' //每页数据量的参数名，默认：limit
		  },
      page: true, //开启分页
      cols: [
        [ //表头
        {
            field: 'Date',
            title: '变更日期',
            align: 'center',
//          width: 150
          }, {
            field: 'OperateType',
            title: '变更类型',
            align: 'center',
            templet:function(d){
            	if(d.OperateType==0){
            		return '<span>减少</span>'
            	}else if(d.OperateType==1){
            		return '<span>增加</span>'
            	}
            },
//          width: 150,
            sort: true
          }, {
            field: 'CurrentScore',
            title: '当前积分',
            align: 'center',
//          width: 150
          }, {
            field: 'OperateScore',
            title: '变更积分',
            align: 'center',
//          width: 177
          }, {
            field: 'LastOperateScore',
            title: '变更后积分',
            align: 'center',
//          width: 150,
            sort: true
          }, {
            field: 'CreateUser',
            title: '操作人',
            align: 'center',
//          width: 150,
//          sort: true
          }, {
            field: 'Memo',
            align: 'center',
            title: '备注',
//          width: 200
          }
        ]
      ]
    });
    },function(data){
    	console.log(data)
    })
    
//  confirm.addEventListener("click",_confirm);
//		console.log("confirm",confirm)

		form.on('select(mon)',function(data){
			mon=data.value;
			console.log(mon)
		})

		$(".confirm").click(_confirm);
    function _confirm(){
    	_obj.CreateUser = localStorage.getItem("user");
    	_obj.CreateTime = getNowFormatDate();
    	_obj.OperateType = mon;
    	_obj.CurrentScore = score;
    	_obj.Memo = memo.value;
    	_obj.OperateScore = money.value;
    	
//  	_obj.CircleGuid = params.id;
//  	_obj.MemLoginId = null;
    	console.log(mon)
    	if(mon==0){
    		if(score - parseFloat(money.value)>=0){
    			_obj.LastOperateScore = score - parseFloat(money.value);
    			changeObj.RankScore = score - parseFloat(money.value);
//  			console.log("_obj",_obj)
		    	console.log(1,changeObj)
		    	
		    	level(changeObj,changeObj.RankScore);   
		    	
		    	changeObj.ModifyTime = getNowFormatDate();
		    	changeObj.ModifyUser = localStorage.getItem("user");
		    	
//		    	console.log("_obj",_obj)
		    	console.log(2,changeObj)
		    	DBHelper.Put("Admin_Xn_Member?id="+params.id,changeObj,function(data){
		    		console.log(3,changeObj)
		    	},function(data){
		    		console.log(4,data)
		    	})
		    	
		    	DBHelper.Post("Admin_Xn_RankScoreModifyLog",_obj,function(data){
		    		console.log("成功",data)
		    		location.href = window.location.href
		    	},function(data){
		    		console.log(data)
		    	})
		//  	layer.msg('添加成功');
					
		//  	window.location.reload();
    		}else{
    			layer.confirm('变更后积分不得小于0！')
    		}
    		
    		
    	}else if(mon==1){
    		_obj.LastOperateScore = score + parseFloat(money.value);
    		changeObj.RankScore = score + parseFloat(money.value);
    		
    		level(changeObj,changeObj.RankScore);  
    		
    		console.log("_obj****",_obj)
	    	console.log("changeObj",changeObj)
	    	
	    	changeObj.ModifyTime = getNowFormatDate();
	    	changeObj.ModifyUser = localStorage.getItem("user");
	    	
	    	DBHelper.Put("Admin_Xn_Member?id="+params.id,changeObj,function(data){
	    		console.log("data",data)
//	    		debugger
	    	},function(data){
	    		console.log(data)
	    	})
	    	
	    	DBHelper.Post("Admin_Xn_RankScoreModifyLog",_obj,function(data){
	    		console.log("成功",data)
	    		location.href = window.location.href
	    	},function(data){
	    		console.log(data)
	    	})
	//  	layer.msg('添加成功');
				
	//  	window.location.reload();
    	}
    	
    	
    }
    
    function renderForm(){
		  layui.use('form', function(){
		   var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
		   form.render();
		  });
		}
    
    
//  nowId.innerText = params.id;
//		console.log($(".nowId"))
    
    
    
  });
</script>
<style scoped>
	.title{
      		margin-left: 30px;
      		margin-top: 30px;
      	}
</style>
      
      <style scoped>
      	.title{
      		margin-left: 30px;
      		margin-top: 30px;
      	}
      	.save-warp{
      		width: 100%;
      		text-align: center;
      		margin-top: 20px;
      	}
      	.save-warp button{
      		display: inline-block;
      		width: 160px;
      	}
      	.changeLev-top{
      		display: flex;
      		width: 100%;
      		justify-content: space-between;
      		margin-top: 10px;
      		margin-bottom: 10px;
      	}
      	.changeSe{
      		width: 200px;
      		height: 50px;
      	}
      	.changeLevTable{
      		margin-top: 10px;
      	}
      	.moneyWarn{
      		color: red;
      	}
      	.money{
      		display: inline-block;
      		width: 200px;
      		margin-right: 20px;
      	}
      	.userInfo{
      		margin-top: 20px;
      	}
      	.userInfoBtns{
      		display: flex;
      		justify-content: center;
      	}
      	.userInfoBtns button,.userInfoBtns a{
      		width: 200px;
      		margin-top: 20px;
      		margin-bottom: 20px;
      	}
		
		
		
		.spt {
			line-height: 35px;
		}
		.clearfix::after {
			content: "";
			clear: both;
			width: 100%;
			height: 0;
			display: block;
		}
		
		.layui-date>input {
			width: 100px;
			margin: 0 10px;
		}
		
		.fl {
			float: left;
		}
      	
      </style>
      
      
      
      
    </div>
  </div>
</div>
